<template>
	<view class="mine-page page">
		<CustomNav title="科普宣教" :isBack="true"></CustomNav>
		<view class="info-block">
			<template v-if="list.length>0">
				<view class="info-list" v-for="item in list" :key="item.id"
					@click="navigate('/page_pack/animal/detail?id='+item.id)">
					<image :src="item.coverImage" class="logo-img"></image>
					<view class="right-item">
						<view class="name">{{item.title}}</view>
						<view class="time" v-if="item.updateTime">{{item.updateTime}}</view>
						<view class="time" v-else>{{item.createTime}}</view>
					</view>
				</view>
			</template>
			<view v-if="more==false&&list.length==0" class="empty">暂无数据</view>
			<view v-else-if="more==false&&list.length>0" class="empty">没有更多了</view>
		</view>
	</view>
</template>

<script>
	import {
		isMore
	} from '@/util/util'
	import {
		getPopularList
	} from '@/api/animal.js'
	export default {
		data() {
			return {
				conf: {
					page: 1,
					limit: 20
				},
				more: true,
				list: []
			}
		},
		methods: {
			handleRefresh() {
				this.conf.page = 1;
				this.more = true
				this.getList('refresh');
			},
			getList(type = '') {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getPopularList(this.conf).then(res => {
					this.list = type == 'refresh' ? res.list : [...this.list, ...res.list];
					this.more = isMore(this.conf.page, this.conf.limit, res.count)
				}).finally(() => {
					uni.stopPullDownRefresh();
				})
			},
		},
		onPullDownRefresh() {
			this.handleRefresh();
		},
		onReachBottom() {
			if (this.more) {
				this.conf.page++;
				this.getList();
			}
		},
		onLoad() {
			this.getList('refresh');
		}
	}
</script>

<style lang="scss" scoped>
	.mine-page {
		overflow: hidden;

		.info-block {
			padding: 30rpx;
			margin-top: 26%;

			.info-list {
				display: flex;
				align-items: center;
				background-color: #fff;
				border-radius: 20rpx;
				margin-bottom: 20rpx;
				padding: 30rpx;

				.logo-img {
					width: 160rpx;
					height: 160rpx;
					border-radius: 20rpx;
					background-color: #f5f5f5;
					margin-right: 20rpx;
				}

				.right-item {
					width: calc(100% - 180rpx);
					display: flex;
					flex-direction: column;

					.name {
						font-size: 34rpx;
						margin-bottom: 30rpx;
					}

					.time {
						font-size: 28rpx;
						color: #999;
					}
				}
			}
		}
	}
</style>